package com.grandtech.insurance.common.factory;


import org.springframework.data.mongodb.core.MongoTemplate;

import java.util.HashMap;
import java.util.Map;

public class MongoClientConnect {

    private static volatile MongoClientConnect instance;

    private Map<String, MongoTemplate> cache;

    private MongoClientConnect() {
        cache = new HashMap<>();
    }

    public static MongoClientConnect getInstance() {
        if (instance == null) {
            synchronized (MongoClientConnect.class) {
                if (instance == null) {
                    instance = new MongoClientConnect();
                }
            }
        }
        return instance;
    }

    public MongoTemplate getMongoClientConnect(String url) {
        return cache.get(url);
    }

    public void cacheMongoClientConnect(String url, MongoTemplate mongoTemplate) {
        cache.put(url, mongoTemplate);
    }
}
